﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Things.Common;
using LTP.Accounts.Bus;
namespace Things.ThingsWeb.GoodsPrice
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    Guid priceID = new Guid(Request.Params["id"]);
                    ShowInfo(priceID);
                }
            }
        }

        private void ShowInfo(Guid GoodsID)
        {
            Things.BLL.GoodsPrice bll = new Things.BLL.GoodsPrice();
            Things.Model.GoodsPrice model = bll.GetModel(GoodsID);
            this.lblID.Text = model.ID.ToString();
            this.lblGoodsID.Text = model.GoodsID.ToString();
            this.txtGoodsPriceType.Text = model.GoodsPriceType;
            this.txtGoodsCurrentPrice.Text = model.GoodsCurrentPrice.ToString();
            this.txtGoodsStandPrice.Text = model.GoodsStandPrice.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtGoodsPriceType.Text.Trim().Length == 0)
            {
                strErr += "商品销售方式不能为空！\\n";
            }
            if (!PageValidate.IsDecimal(txtGoodsCurrentPrice.Text))
            {
                strErr += "当前价格格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtGoodsStandPrice.Text))
            {
                strErr += "市场价格格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            Guid ID = new Guid(this.lblID.Text);
            Guid GoodsID = new Guid(this.lblGoodsID.Text);
            string GoodsPriceType = this.txtGoodsPriceType.Text;
            decimal GoodsCurrentPrice = decimal.Parse(this.txtGoodsCurrentPrice.Text);
            decimal GoodsStandPrice = decimal.Parse(this.txtGoodsStandPrice.Text);

            Things.BLL.GoodsPrice bll = new Things.BLL.GoodsPrice();
            Things.Model.GoodsPrice model = bll.GetModel(ID);
            if (model != null)
            {
                model.GoodsPriceType = GoodsPriceType;
                model.GoodsCurrentPrice = GoodsCurrentPrice;
                model.GoodsStandPrice = GoodsStandPrice;

                bll.Update(model);
                Things.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx?ID=" + this.lblGoodsID.Text);
            }
        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx?ID=" + this.lblGoodsID.Text);
        }
    }
}
